import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter_swiper/flutter_swiper.dart';

class DiTeiPage extends StatefulWidget {
  @override
  _DiTeiPageState createState() => _DiTeiPageState();
}

class _DiTeiPageState extends State<DiTeiPage> {
  late ScrollController _controller;

  late ScrollController _controller1;

  double count = 1;

  bool start = true;

  bool leneraStart = false;

  List<Map> imageMap = [
    {"id": 1, "url": "lib/assets/icon/sw1.png"},
    {"id": 2, "url": "lib/assets/icon/sw2.png"},
    {"id": 3, "url": "lib/assets/icon/sw3.png"},
  ];

  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    _controller = ScrollController(initialScrollOffset: 300);
    getListener();

    _controller1 = ScrollController(initialScrollOffset: 0);
    getListener2();
  }

  void getListener2() {
    _controller1.addListener(() {
      print(_controller1.offset.toString());
      if (_controller1.offset.toInt() > 100) {
        setState(() {
          leneraStart = true;
        });
      } else if (_controller1.offset.toInt() < 10) {
        leneraStart = false;
      }
    });
  }

  void getListener() {
    const timeout = const Duration(seconds: 1);
    Timer.periodic(timeout, (timer) {
      //callback function
      //1s 回调一次
      // print('afterTimer='+DateTime.now().toString());
      setState(() {
        count += 1;
      });
      if (count < 30) {
        _controller.animateTo(4000,
            duration: Duration(seconds: 50), curve: Curves.linear);
      } else {
        // _controller.animateTo(300,duration: Duration(seconds: 1),curve: Curves.linear);
        _controller.jumpTo(300);
        setState(() {
          count = 1;
        });
      }

      //print(count.toString());
    });
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    _controller.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: MediaQuery.removePadding(
      removeTop: true,
      context: context,
      child: Stack(
        children: [
          ListView(
            controller: _controller1, //
            shrinkWrap: true,
            children: [
              Container(
                width: MediaQuery.of(context).size.width,
                height: 975,
                decoration: BoxDecoration(
                    gradient: LinearGradient(
                        //渐变位置
                        begin: Alignment.topRight, //右上
                        end: Alignment.bottomLeft, //左下
                        stops: [
                      0.0,
                      1.0
                    ], //[渐变起始点, 渐变结束点]
                        //渐变颜色[始点颜色, 结束颜色]
                        colors: [
                      //Color.fromRGBO(0, 201, 87, 1),
                      //Colors.yellow,
                      Color.fromRGBO(87, 187, 114, 1),
                      Color.fromRGBO(236, 238, 237, 1)
                    ])),
                child: Stack(
                  children: [
                    Positioned(
                      top: 10,
                      child: Padding(
                        padding: EdgeInsets.only(
                            left: 10, top: 20, right: 100, bottom: 0),
                        child: Container(
                          width: MediaQuery.of(context).size.width,
                          height: 60,
                          //color: Colors.blueAccent,
                          child: Padding(
                            padding: EdgeInsets.only(left: 0, right: 20),
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Container(
                                  width: 220,
                                  height: 60,
                                  //color: Colors.orange,
                                  child: Row(
                                    mainAxisAlignment: MainAxisAlignment.start,
                                    crossAxisAlignment:
                                        CrossAxisAlignment.center,
                                    children: [
                                      Container(
                                        width: 65,
                                        height: 60,
                                        child: Row(
                                          children: [
                                            Text(
                                              "深圳",
                                              style: TextStyle(
                                                  fontSize: 18,
                                                  color: Colors.white,
                                                  fontWeight: FontWeight.w600),
                                            ),
                                            SizedBox(
                                              width: 5,
                                            ),
                                            Container(
                                              width: 13,
                                              height: 13,
                                              child: Image.asset(
                                                  "lib/assets/icon/sjx.png"),
                                            )
                                          ],
                                        ),
                                      ),
                                      Container(
                                        width: 130,
                                        height: 30,
                                        decoration: BoxDecoration(
                                            borderRadius:
                                                BorderRadius.circular(15),
                                            color: Colors.white),
                                        child: Row(
                                          mainAxisAlignment:
                                              MainAxisAlignment.center,
                                          children: [
                                            Text(
                                              "深圳通乘车码",
                                              style: TextStyle(
                                                  color: Colors.green),
                                            ),
                                            Container(
                                              width: 15,
                                              height: 15,
                                              child: Image.asset(
                                                  "lib/assets/icon/bottom.png"),
                                            )
                                          ],
                                        ),
                                      )
                                    ],
                                  ),
                                ),
                                Container(
                                  width: 30,
                                  height: 30,
                                  //color: Colors.teal,
                                  child: Image.asset(
                                      "lib/assets/icon/message.png"),
                                )
                              ],
                            ),
                          ),
                        ),
                      ),
                    ),
                    Positioned(
                      top: 70,
                      child: Padding(
                        padding: EdgeInsets.only(
                            left: 0, right: 3, top: 0, bottom: 0),
                        child: Container(
                          width: MediaQuery.of(context).size.width,
                          height: 80,
                          child: Image.asset("lib/assets/icon/smcdt.png"),
                        ),
                      ),
                    ),
                    Positioned(
                      top: 100,
                      child: Padding(
                        padding: EdgeInsets.only(left: 55, right: 30),
                        child: Text(
                          "刷码乘地铁 | " +
                              DateTime.now().toString().substring(0, 19),
                          style: TextStyle(
                              fontSize: 16, fontWeight: FontWeight.w600),
                        ),
                      ),
                    ),
                    Positioned(
                      top: 132,
                      child: Container(
                          width: 400,
                          height: 325,
                          child: Padding(
                            padding: EdgeInsets.only(
                                left: 0, top: 0, bottom: 0, right: 40),
                            child: Scrollbar(
                              showTrackOnHover: false,
                              child: ListView(
                                shrinkWrap: true,
                                physics: NeverScrollableScrollPhysics(),
                                controller: _controller,
                                children: [
                                  Container(
                                    width: MediaQuery.of(context).size.width,
                                    height: 100,
                                  ),
                                  Padding(
                                    padding: EdgeInsets.only(
                                        left: 10,
                                        top: 100,
                                        bottom: 300,
                                        right: 10),
                                    child: Container(
                                      child: Image(
                                        image:
                                            AssetImage("lib/assets/ditie.png"),
                                        fit: BoxFit.cover,
                                      ),
                                    ),
                                  )
                                ],
                              ),
                            ),
                          )),
                    ),
                    Positioned(
                      top: 144,
                      left: 75,
                      child: Container(
                        alignment: Alignment.center,
                        width: 210,
                        height: 35,
                        decoration: BoxDecoration(
                            color: Color.fromRGBO(244, 253, 248, 0.2)),
                        child: Text(
                          "绿码",
                          style: TextStyle(
                              color: Colors.white,
                              fontSize: 20,
                              fontWeight: FontWeight.w400),
                        ),
                      ),
                    ),
                    Positioned(
                      top: 186,
                      left: 75,
                      child: Container(
                        width: 210,
                        height: 210,
                        child: Image.asset("lib/assets/icon/erweima111.jpg"),
                      ),
                    ),
                    Positioned(
                      top: 407,
                      left: 143,
                      child: Container(
                        width: 80,
                        height: 30,
                        decoration: BoxDecoration(
                            color: Color.fromRGBO(243, 252, 247, 1),
                            borderRadius: BorderRadius.circular(15)),
                        child: Padding(
                          padding: EdgeInsets.only(left: 13, right: 13),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceAround,
                            children: [
                              Container(
                                width: 16,
                                height: 16,
                                child: Image.asset("lib/assets/icon/show.png"),
                              ),
                              Text("刷新")
                            ],
                          ),
                        ),
                      ),
                    ),
                    Positioned(
                      top: 453,
                      left: 5,
                      child: Padding(
                        padding: EdgeInsets.only(left: 0, right: 0),
                        child: Container(
                          width: 350,
                          height: 190,
                          decoration: BoxDecoration(
                              image: DecorationImage(
                                  image: AssetImage(
                                      "lib/assets/icon/12312512.png"),
                                  fit: BoxFit.fill)),
                          //color: Colors.orange,
                        ),
                      ),
                    ),
                    Positioned(
                      top: 445,
                      child: Container(
                        width: MediaQuery.of(context).size.width,
                        height: 180,
                        //color: Colors.yellow,
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: [
                            Container(
                              width: 140,
                              height: 120,
                              color: Color.fromRGBO(225, 239, 252, 1),
                              child: Column(
                                mainAxisAlignment: MainAxisAlignment.center,
                                children: [
                                  Container(
                                    width: 100,
                                    height: 20,
                                    //color: Colors.orange,
                                    child: Row(
                                      mainAxisAlignment:
                                          MainAxisAlignment.center,
                                      children: [
                                        Container(
                                          width: 13,
                                          height: 13,
                                          child: Image.asset(
                                              "lib/assets/icon/tg.png"),
                                        ),
                                        Text(" 核酸检测 >")
                                      ],
                                    ),
                                  ),
                                  Padding(
                                    padding: EdgeInsets.only(right: 10),
                                    child: Container(
                                      width: 100,
                                      height: 60,
                                      //color: Colors.green,
                                      child: Row(
                                        mainAxisAlignment:
                                            MainAxisAlignment.center,
                                        children: [
                                          Container(
                                            width: 60,
                                            height: 60,
                                            child: Image.asset(
                                                "lib/assets/icon/24.png"),
                                          ),
                                          Column(
                                            mainAxisAlignment:
                                                MainAxisAlignment.center,
                                            children: [
                                              Text(
                                                "小时",
                                                style: TextStyle(
                                                    color: Color.fromRGBO(
                                                        30, 84, 233, 1),
                                                    fontWeight:
                                                        FontWeight.w600),
                                              ),
                                              Container(
                                                height: 5,
                                              ),
                                              Text(
                                                "阴性",
                                                style: TextStyle(
                                                    color: Color.fromRGBO(
                                                        30, 84, 233, 1),
                                                    fontWeight:
                                                        FontWeight.w600),
                                              )
                                            ],
                                          )
                                        ],
                                      ),
                                    ),
                                  ),
                                  Text(
                                    "" +
                                        DateTime.now().year.toString() +
                                        "-" +
                                        DateTime.now().month.toString() +
                                        "-" +
                                        (DateTime.now().day).toString() +
                                        " " +
                                        "01:10:28",
                                    style: TextStyle(fontSize: 13),
                                  )
                                ],
                              ),
                            ),
                            Container(
                              width: 20,
                              color: Colors.white,
                              height: 30,
                            ),
                            Container(
                              width: 140,
                              height: 120,
                              color: Color.fromRGBO(232, 243, 235, 1),
                              child: Column(
                                mainAxisAlignment: MainAxisAlignment.center,
                                children: [
                                  Container(
                                    width: 100,
                                    height: 20,
                                    //color: Colors.orange,
                                    child: Row(
                                      mainAxisAlignment:
                                          MainAxisAlignment.center,
                                      children: [
                                        Container(
                                          width: 13,
                                          height: 13,
                                          child: Image.asset(
                                              "lib/assets/icon/tg.png"),
                                        ),
                                        Text(" 疫苗情况 >")
                                      ],
                                    ),
                                  ),
                                  Container(
                                    alignment: Alignment.center,
                                    height: 60,
                                    child: Text(
                                      "已接种3剂",
                                      style: TextStyle(
                                          fontSize: 24,
                                          fontWeight: FontWeight.w600,
                                          color: Colors.green),
                                    ),
                                  ),
                                  Text(
                                    "2021-12-01 15:03:39",
                                    style: TextStyle(fontSize: 13),
                                  )
                                ],
                              ),
                            ),
                          ],
                        ),
                      ),
                    ),
                    Positioned(
                      top: 603,
                      child: Container(
                        alignment: Alignment.center,
                        width: MediaQuery.of(context).size.width,
                        height: 20,
                        child: Text(
                          "以上健康数据由粤康码 (深圳) 提供",
                          style: TextStyle(
                              color: Color.fromRGBO(168, 168, 168, 1)),
                        ),
                      ),
                    ),
                    Positioned(
                      top: 650,
                      child: Padding(
                        padding: EdgeInsets.only(left: 10, right: 10),
                        child: Container(
                          width: MediaQuery.of(context).size.width,
                          height: 100,
                          //color: Colors.orange,
                          child: new Swiper(
                            autoplay: true,
                            itemBuilder: (BuildContext context, int index) {
                              //print(index);
                              return new InkWell(
                                hoverColor: Colors.deepPurple,
                                focusColor: Colors.deepPurple,
                                onTap: () {
                                  // Navigator.of(context).push(MaterialPageRoute(
                                  //   builder: (context) {
                                  //     return DigitalDetail();
                                  //   },
                                  //   //RouteSettings里面可以修改路由的名称 参数
                                  //   settings: RouteSettings(
                                  //     arguments: {"id": "2345676"},
                                  //   ),
                                  //   //  释放没有用的路由内存
                                  //   maintainState: false,
                                  //   fullscreenDialog: false,
                                  // ),
                                  // );

                                  //print("打印。。跳转。。" + index.toString());
                                },
                                child: Padding(
                                  padding: EdgeInsets.only(right: 20),
                                  child: Container(
                                    width:
                                        MediaQuery.of(context).size.width - 30,
                                    child: Image.asset(
                                      imageMap[index]["url"].toString(),
                                      fit: BoxFit.fill,
                                      width: 200,
                                    ),
                                  ),
                                ),
                              );
                            },
                            containerHeight: 10,
                            //autoplay: true,
                            itemCount: imageMap.length,
                            //指示器样式
                            pagination: new SwiperPagination(
                                margin: EdgeInsets.only(bottom: 0)),
                            //左右箭头
                            //control: new SwiperControl(),
                          ),
                        ),
                      ),
                    ),
                    //Positioned(top: 700,child: Container(width: MediaQuery.of(context).size.width,height: 90,color: Colors.blue,),),
                    Positioned(
                      top: 760,
                      child: Padding(
                        padding: EdgeInsets.only(left: 10, right: 10),
                        child: Container(
                          width: MediaQuery.of(context).size.width - 20,
                          height: 100,
                          //color: Colors.orange,
                          decoration: BoxDecoration(
                              image: DecorationImage(
                                  image: AssetImage(
                                      "lib/assets/icon/bottomlist.png"))),
                          //child: Image.asset("lib/assets/icon/bottomlist.png",fit: BoxFit.fill,),
                        ),
                      ),
                    ),
                    Positioned(
                      top: 850,
                      child: Container(
                        alignment: Alignment.center,
                        width: MediaQuery.of(context).size.width,
                        height: 70,
                        child: Text("Flutter version: V0.2.4"),
                      ),
                    ),
                  ],
                ),
              ),
            ],
          ),
          leneraStart
              ? MediaQuery.removePadding(
            removeTop: true,
            context: context,
                child: Positioned(
                    top: 0,
                    child: Container(
                      width: MediaQuery.of(context).size.width,
                      height: 80,
                      color: Color.fromRGBO(255, 255, 255, 1),
                      child: Center(
                          child: Padding(
                        padding: EdgeInsets.only(top: 40),
                        child: Text("乘车码",style: TextStyle(fontSize: 18),),
                      )),
                    ),
                  ),
              )
              : Text(""),
          Positioned(
            bottom: 0,
            child: Container(
              width: MediaQuery.of(context).size.width,
              height: 55,
              // color: Colors.white,
              child: Container(
                width: MediaQuery.of(context).size.width,
                height: 55,
                color: Color.fromRGBO(255, 255, 255, 1),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: [
                    Container(
                      width: 25,
                      height: 45,
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Image.asset("lib/assets/icon/home.png"),
                          SizedBox(height: 4,),
                          Text(
                            "首页",
                            style: TextStyle(fontSize: 10),
                          ),
                          SizedBox(height: 4,),
                        ],
                      ),
                    ),
                    Container(
                      width: 25,
                      height: 45,
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Image.asset("lib/assets/icon/dt.png"),
                          SizedBox(height: 4,),
                          Text(
                            "出行",
                            style: TextStyle(fontSize: 10),
                          ),
                          SizedBox(height: 4,),
                        ],
                      ),
                    ),
                    Container(
                      width: 40,
                      height: 55,
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.start,
                        children: [
                          //Container(child: Container(width: 35,height: 35,decoration: BoxDecoration(borderRadius: BorderRadius.circular(8),color: Colors.green,),child: Padding(padding: EdgeInsets.only(top: 7,bottom: 7,right: 7,left: 7),child: Container(width: 35,height: 35,child: Image.asset("lib/assets/icon/wm.png",fit: BoxFit.fill,),),))),
                          Text(
                            "",
                            style: TextStyle(fontSize: 10),
                          )
                        ],
                      ),
                    ),
                    Container(
                      width: 25,
                      height: 45,
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.end,
                        children: [
                          Image.asset("lib/assets/icon/ax.png"),
                          SizedBox(height: 4,),
                          Text(
                            "生活",
                            style: TextStyle(fontSize: 10),
                          ),
                          SizedBox(height: 4,),
                        ],
                      ),
                    ),
                    Container(
                      width: 35,
                      height: 50,
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Container(width: 32,height: 32,child: Image.asset("lib/assets/icon/my.png",fit: BoxFit.fill,),),
                          Text(
                            "我的",
                            style: TextStyle(fontSize: 10),
                          ),
                          SizedBox(height: 6,),
                        ],
                      ),
                    ),
                  ],
                ),
              ),
            ),
          ),
          Positioned(
            left: 152,
            bottom: 5,
            child: Container(
              width: 45,
              height: 58,
              //color: Colors.orange,

              child: Column(
                mainAxisAlignment: MainAxisAlignment.start,
                children: [
                  Container(
                      child: Container(
                          width: 45,
                          height: 45,
                          decoration: BoxDecoration(
                            borderRadius: BorderRadius.circular(10),
                            color: Colors.green,
                            border: Border(
                              top: BorderSide(width: 3, color: Colors.white),
                              bottom: BorderSide(width: 3, color: Colors.white),
                              right: BorderSide(width: 3, color: Colors.white),
                              left: BorderSide(width: 3, color: Colors.white),
                            ),
                          ),
                          child: Padding(
                            padding: EdgeInsets.only(
                                top: 7, bottom: 7, right: 7, left: 7),
                            child: Container(
                              width: 35,
                              height: 35,
                              child: Image.asset(
                                "lib/assets/icon/wm.png",
                                fit: BoxFit.fill,
                              ),
                            ),
                          ))),
                  Text(
                    "乘车码",
                    style: TextStyle(fontSize: 10),
                  )
                ],
              ),
            ),
          ),
        ],
      ),
    ));
  }
}
